using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace Kxzz.Controls
{
	/**
	 *  A Rollover is a PictureBox that changes images when the mouse enters / leaves its area
	 */
	public class Rollover : PictureBox
	{
		#region Properties

		Image _rollOverImage;
		Image _rollOutImage;
		Cursor _rollOverCursor;

		#endregion

		public Rollover()
		{
			_rollOverImage = null;
			_rollOutImage = this.Image;
			this.MouseEnter += new System.EventHandler(this.mouseRollOver);
			this.MouseLeave += new System.EventHandler(this.mouseRollOut);
		}

		#region Property Definitions

		public Image RollOverImage
		{
			get
			{
				return _rollOverImage;
			}
			set
			{
				_rollOverImage = value;
				this.Invalidate();
			}
		}

		public Cursor RollOverCursor
		{
			get
			{
				return _rollOverCursor;
			}
			set
			{
				_rollOverCursor = value;
				this.Invalidate();
			}
		}
		
		#endregion

		/**
		 *  Event handler that manages image swapping when the mouse hovers over the Rollover area
		 */
		private void mouseRollOver(object sender, EventArgs e)
		{
			this.Cursor = _rollOverCursor;
			if (RollOverImage != null)
			{
				_rollOutImage = this.Image;
				this.Image = RollOverImage;
			}
		}

		/**
		 *  Event handler that manages image swapping when the mouse leaves the Rollover area
		 */
		private void mouseRollOut(object sender, EventArgs e)
		{
			this.Cursor = Cursors.Default;
			if (_rollOutImage != null)
			{
				this.Image = _rollOutImage;
			}
		}


	}
}
